package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.StorePopupWindow;
import com.qj.yantaishan.service.IStorePopupWindowService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 店铺弹窗海报Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/StorePopupWindow")
public class StorePopupWindowController extends BaseController
{
    private String prefix = "yantaishan/StorePopupWindow";

    @Autowired
    private IStorePopupWindowService storePopupWindowService;

    @RequiresPermissions("yantaishan:window:view")
    @GetMapping()
    public String window()
    {
        return prefix + "/window";
    }

    /**
     * 查询店铺弹窗海报列表
     */
    @RequiresPermissions("yantaishan:window:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StorePopupWindow storePopupWindow)
    {
        startPage();
        List<StorePopupWindow> list = storePopupWindowService.selectStorePopupWindowList(storePopupWindow);
        return getDataTable(list);
    }

    /**
     * 导出店铺弹窗海报列表
     */
    @RequiresPermissions("yantaishan:window:export")
    @Log(title = "店铺弹窗海报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StorePopupWindow storePopupWindow)
    {
        List<StorePopupWindow> list = storePopupWindowService.selectStorePopupWindowList(storePopupWindow);
        ExcelUtil<StorePopupWindow> util = new ExcelUtil<StorePopupWindow>(StorePopupWindow.class);
        return util.exportExcel(list, "店铺弹窗海报数据");
    }

    /**
     * 新增店铺弹窗海报
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存店铺弹窗海报
     */
    @RequiresPermissions("yantaishan:window:add")
    @Log(title = "店铺弹窗海报", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StorePopupWindow storePopupWindow)
    {
        return toAjax(storePopupWindowService.insertStorePopupWindow(storePopupWindow));
    }

    /**
     * 修改店铺弹窗海报
     */
    @RequiresPermissions("yantaishan:window:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        StorePopupWindow storePopupWindow = storePopupWindowService.selectStorePopupWindowById(id);
        mmap.put("storePopupWindow", storePopupWindow);
        return prefix + "/edit";
    }

    /**
     * 修改保存店铺弹窗海报
     */
    @RequiresPermissions("yantaishan:window:edit")
    @Log(title = "店铺弹窗海报", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StorePopupWindow storePopupWindow)
    {
        return toAjax(storePopupWindowService.updateStorePopupWindow(storePopupWindow));
    }

    /**
     * 删除店铺弹窗海报
     */
    @RequiresPermissions("yantaishan:window:remove")
    @Log(title = "店铺弹窗海报", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(storePopupWindowService.deleteStorePopupWindowByIds(ids));
    }
}
